﻿#ifndef FINSUDP_H
#define FINSUDP_H

#include <QObject>
#include <QHostAddress>
#include <QUdpSocket>
#include <QDebug>
#include <QTimer>
#include <QTime>
#include "UdpClient.h"
#include "PLCClientBase.h"


class FinsUdp : public PLCClientBase
{
    Q_OBJECT
public:
    explicit FinsUdp(const QString& name = "", QObject *parent = nullptr);
    virtual ~FinsUdp();
    
public:
    void onStateChanged(ComState state);
protected:
    virtual void processData(const PLCRequestData& requestData){}
    void initCom() override;
    void sendReadData(const PLCRequestData& data) override;
    void sendWriteData(const PLCRequestData& data) override;
private:
    QString getReadHoldRegisterCommand(int startAddr, int length);
    QString getReadCoilsRegisterCommand(int startAddr, int length);
    QString getReadInputRegisterCommand(int startAddr, int length);
    QString getWriteHoldRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    QString getWriteCoilsRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    QString getWriteInputRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    void onReceiveData(const QByteArray& data);
    UdpClient* mUdpClient;
};

#endif // FINSUDP_H
